package 力扣日常刷题.木23一月.第14天314;

/**
 * @author 帅小伙
 * @date 2022/3/14
 * @description
 * 原地反转
 */
public class Demo70旋转图像 {

    public void rotate(int[][] matrix) {
        int len = matrix.length;
        //主对角线翻转
        for (int i = 0; i < len; i++) {
            for (int j = i; j < len; j++) {
                int t = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = t;
            }
        }

        //左右反转
        int midLen = len % 2 == 0? len / 2 : len / 2 + 1;
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < midLen; j++) {
                int t = matrix[i][j];
                matrix[i][j] = matrix[i][len - 1 - j];
                matrix[i][len - 1 - j] = t;
            }
        }
    }

}
